package com.ysqcould.web.controller.approval;


import com.ysqcould.approval.domain.GeneralTask;
import com.ysqcould.approval.domain.vo.GeneralTaskVo;
import com.ysqcould.approval.service.IGeneralTaskService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通用任务Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/approval/task")
public class GeneralTaskController extends BaseController
{
    @Autowired
    private IGeneralTaskService generalTaskService;

    /**
     * 查询通用任务列表
     */
    @PreAuthorize("@ss.hasPermi('approval:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(GeneralTask generalTask)
    {
        startPage();
        List<GeneralTaskVo> list = generalTaskService.selectGeneralTaskList(generalTask);
        return getDataTable(list);
    }

    /**
     * 获取通用任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('approval:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(generalTaskService.selectGeneralTaskById(id));
    }

    /**
     * 新增通用任务
     */
    @PreAuthorize("@ss.hasPermi('approval:task:add')")
    @Log(title = "通用任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GeneralTask generalTask)
    {
        generalTask.setAsId(getUserId());
        return toAjax(generalTaskService.insertGeneralTask(generalTask));
    }

    /**
     * 修改通用任务
     */
    @PreAuthorize("@ss.hasPermi('approval:task:edit')")
    @Log(title = "通用任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GeneralTask generalTask)
    {
        return toAjax(generalTaskService.updateGeneralTask(generalTask));
    }

    /**
     * 删除通用任务
     */
    @PreAuthorize("@ss.hasPermi('approval:task:remove')")
    @Log(title = "通用任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(generalTaskService.deleteGeneralTaskByIds(ids));
    }
}
